package com.mall.controller;

import com.mall.entity.Users;
import com.mall.mapper.UsersMapper;
import com.mall.ultis.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

import com.mall.ultis.JwtHelper;

@RestController
@RequestMapping("/api")
public class UserController {

    @Resource
    UsersMapper usersMapper;

    @Resource
    JwtHelper jwtHelper;

    @GetMapping("user_info")
    public Result user_info(ServletRequest request) {
        HttpServletRequest httpRequest = (HttpServletRequest) request;

        Map ctx = jwtHelper.validateTokenAndGetClaims( httpRequest );

        return Result.success(ctx.get( "data" ));
    }
}
